package org.jfunny.core.sys.impl.clojure;

import java.util.ArrayList;
import java.util.List;

import org.jfunny.core.ds.Arg;
import org.jfunny.core.ds.Statement;

public final class SysFunctionHelper {

	public static List<Arg> getArgs(Statement statement) {
		List<Arg> result = new ArrayList<Arg>();
		for (Statement s : statement.getChildren()) {
			if(s instanceof Arg) {
				result.add((Arg)s);
			}
		}
		return result;
	}
	
	public static List<String> getArgContents(Statement statement) {
		List<String> result = new ArrayList<String>();
		for (Statement s : statement.getChildren()) {
			if(s instanceof Arg) {
				result.add(((Arg)s).getContent());
			}
		}
		return result;
	}
	
	public static Arg getArg(Statement statement, int index) {
		int i = 0;
		for (Statement s : statement.getChildren()) {
			if (s instanceof Arg) {
				if (index == i) {
					return ((Arg)s);
				}
				i++;
			}
		}
		return null;
	}
	
	public static String getArgContent(Statement statement, int index) {
		int i = 0;
		for (Statement s : statement.getChildren()) {
			if (s instanceof Arg) {
				if (index == i) {
					return (((Arg)s)).getContent();
				}
				i++;
			}
		}
		return null;
	}
	
	public static List<Arg> getArgsInLoop(Statement statement, int start, int count, int index) {
		List<Arg> result = new ArrayList<Arg>();
		
		int i = 0;
		for (Statement s : statement.getChildren()) {
			if (s instanceof Arg) {
				if ((start >= i) && ((i - start) % count == index)) {
					result.add((Arg)s);
				}
				i++;
			}
		}
		return result;
	}
	
	public static List<String> getArgContentsInLoop(Statement statement, int start, int count, int index) {
		List<String> result = new ArrayList<String>();
		
		int i = 0;
		for (Statement s : statement.getChildren()) {
			if (s instanceof Arg) {
				if ((start >= i) && ((i - start) % count == index)) {
					result.add(((Arg)s).getContent());
				}
				i++;
			}
		}
		return result;
	}
}
